/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 *@author Juan Carlos Parra code: 258048
 */
public class Validator {
    static double min;
    public static Boolean validate(Integer lenght, ForecastResults results){
        if(results.getInputs().length < lenght)
            return false;
        return true;
    }
 
    public static Boolean validate(Double[] inputs){
        if(inputs.length < 5)
            return false;
        return true;
    }
    
    public static ForecastResults getMin(List<ForecastResults> list){
        Map<Double,ForecastResults> predictions = new HashMap();
        
        for( ForecastResults s : list){                 
            predictions.put(error(s.inputs,s.outputs),s);
        }
        
        min=Collections.min(predictions.keySet());
        return predictions.get(min);
               
    }
    
        public static Double error( Double At[], Double Ft[] ){
           double sum=0, err=  100/At.length;        
           for(int i=0; i<At.length;i++){
               sum=sum+Math.abs((At[i]-Ft[i])/(At[i]));           
           }
           err=err*sum;        
           return err;
           
    }
        public static Double getMinErr(){
          return min;
    }
        
}
